﻿@{
    Layout = "~/Views/Shared/_FormWhite.cshtml";
}

<div class="container-div">
    <div class="row">
        <div id="searchDiv" class="col-sm-12 search-collapse">
            <div class="select-list">
                <ul>
                    <li class="select-time">
                        <label>录像日期： </label>
                        <input id="backTime" col="backTime" type="text" class="time-input" placeholder="录像日期" />
                    </li>
                </ul>
            </div>
        </div>
        @*<div class="btn-group-sm hidden-xs" id="toolbar">
            <a id="btnBackPlay" class="btn btn-info" onclick="BackPlay()"><i class="fa fa-file-video-o"></i> 录像播放</a>
        </div>*@
        <div class="col-sm-12 select-table table-striped">
            <table id="gridTable" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>



<script type="text/javascript">
    var deviceId = ys.request("deviceId");
    var channelId = ys.request("channelId");

    $(function () {
        laydate.render({ elem: '#backTime', format: 'yyyy-MM-dd', max: 0, value: getRecentDay(0), done: function (value, date) { initGrid(); } });
        initGrid();
    });

    function initGrid() {
        var queryUrl = '@Url.Content("~/CameraManage/VideoChannels/RecordList")' + '?deviceId=' + deviceId + '&channelId=' + channelId + '&time=' + $('#backTime').val();
        $('#gridTable').ysTable({
            url: queryUrl,
            columns: [
                { radio: true, visible: true },
                { field: 'taskId', title: '任务ID' },
                { field: 'ssrcId', title: 'SSRCID' },
                { field: 'date_s', title: '开始时间' },
                { field: 'date_e', title: '结束时间' },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs" href="#" onclick="BackPlay(\'' + row.taskId + '\',' + row.ssrcId + ')"><i class="fa fa-file-video-o"></i>播放</a> ');
                        return actions.join('');
                    }
                }
            ],
            queryParams: function (params) {
                //var pagination = $('#gridTable').ysTable('getPagination', params);
                //var queryString = $('#searchDiv').getWebControls(pagination);
                //return queryString;
            }
        });
    }

    //录像播放
    function BackPlay(taskId,ssrcId) {
        ys.openDialog({
            title: '录像回放',
            content: '@Url.Content("~/CameraManage/VideoChannels/LiveVideo")' + '?taskId=' + taskId + '&ssrcId=' + ssrcId + '&Type=Record',
            width: '950px',
            height: '600px',
            callback: function (index, layero) {

            }
         });
    }


    /**获取近N天*/
    function getRecentDay(day) {
        var today = new Date();
        var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
        today.setTime(targetday_milliseconds);
        var tYear = today.getFullYear();
        var tMonth = today.getMonth();
        var tDate = today.getDate();
        tMonth = doHandleMonth(tMonth + 1);
        tDate = doHandleMonth(tDate);
        return tYear + "-" + tMonth + "-" + tDate;
    }
    function doHandleMonth(month) {
        var m = month;
        if (month.toString().length == 1) {
            m = "0" + month;
        }
        return m;
    }

</script>

